local skel = fk.CreateSkill {
  name = "lb__xiaowu",
}

Fk:loadTranslationTable {
  ["lb__xiaowu"] = "潇舞",
  [":lb__xiaowu"] = "准备阶段，你可以展示手牌直到回合结束，若如此做，你本回合使用牌后摸手牌中类型数张牌，之后将手牌弃至其中花色数张。若你非本回合第一次未因此弃牌，你弃置两张牌并重置<a href=':lb__jumu'><font color='red'>〖聚目〗</font></a>。",

  ["$lb__xiaowu1"] = "气氛已经烘托到位。",
  ["$lb__xiaowu2"] = "小心错过入场的最佳时机。",
  ["$lb__xiaowu3"] = "保持步调一致。",
  ["$lb__xiaowu4"] = "敬请期待。",
}

skel:addEffect(fk.EventPhaseStart, {
  audio_index = { 1, 2 },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "lb__xiaowu_show-turn", 1)
  end,
})

skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  audio_index = { 3, 4 },
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player:getMark("lb__xiaowu_show-turn") > 0 and not player.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card_type, card_suit = {}, {}
    for _, id in ipairs(player:getCardIds("h")) do
      table.insertIfNeed(card_type, Fk:getCardById(id).type)
    end
    if #card_type > 0 then
      player:drawCards(#card_type, "lb__xiaowu")
    end
    for _, id in ipairs(player:getCardIds("h")) do
      table.insertIfNeed(card_suit, Fk:getCardById(id).suit)
    end
    local n = player:getHandcardNum() - #card_suit
    if n > 0 then
      if #room:askToDiscard(player, {
            min_num = n,
            max_num = n,
            include_equip = false,
            skill_name = skel.name,
            cancelable = false,
          }) == 0 then
        room:addPlayerMark(player, "lb__xiaowu-turn", 1)
      end
    else
      room:addPlayerMark(player, "lb__xiaowu-turn", 1)
      if player:getMark("lb__xiaowu-turn") > 1 then
        room:askToDiscard(player, {
          min_num = 2,
          max_num = 2,
          include_equip = false,
          skill_name = skel.name,
          cancelable = false,
        })
        room:setPlayerMark(player, "@lb__jumu-turn", 0)
      end
    end
  end,
})

skel:addEffect("visibility", {
  card_visible = function (self, player, card)
    local from = Fk:currentRoom():getCardOwner(card)
    if from and from:getMark("lb__xiaowu_show-turn") > 0 and table.contains(from:getCardIds("h"), card.id) then
      return true
    end
  end,
})

skel:addLoseEffect(function(self, player, is_death)
  player.room:setPlayerMark(player, "lb__xiaowu_show-turn", 0)
end)

return skel
